home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / Zend / zend_alloc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-19  |  6.0 KB  |  145 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_ALLOC_H
  22. #define ZEND_ALLOC_H
  23.  
  24. #include <stdio.h>
  25.  
  26. #ifdef ZTS
  27. #include "../TSRM/TSRM.h"
  28. #endif
  29.  
  30. #include "zend_globals_macros.h"
  31.  
  32. #define MEM_BLOCK_START_MAGIC    0x7312F8DCL
  33. #define MEM_BLOCK_END_MAGIC    0x2A8FCC84L
  34. #define MEM_BLOCK_FREED_MAGIC    0x99954317L
  35. #define MEM_BLOCK_CACHED_MAGIC    0xFB8277DCL
  36.  
  37. typedef struct _zend_mem_header {
  38. #if ZEND_DEBUG
  39.     long magic;
  40.     char *filename;
  41.     uint lineno;
  42.     int reported;
  43.     char *orig_filename;
  44.     uint orig_lineno;
  45. # ifdef ZTS
  46.     THREAD_T thread_id;
  47. # endif
  48. #endif
  49.     struct _zend_mem_header *pNext;
  50.     struct _zend_mem_header *pLast;
  51.     unsigned int size:30;
  52.     unsigned int persistent:1;
  53.     unsigned int cached:1;
  54. } zend_mem_header;
  55.  
  56. typedef union _align_test {
  57.     void *ptr;
  58.     double dbl;
  59.     long lng;
  60. } align_test;
  61.  
  62. #define MAX_CACHED_MEMORY    11
  63. #define MAX_CACHED_ENTRIES    256
  64. #define PRE_INIT_CACHE_ENTRIES    32
  65.  
  66. #if (defined (__GNUC__) && __GNUC__ >= 2)
  67. #define PLATFORM_ALIGNMENT (__alignof__ (align_test))
  68. #else
  69. #define PLATFORM_ALIGNMENT (sizeof(align_test))
  70. #endif
  71.  
  72. #define PLATFORM_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT)
  73.  
  74.  
  75. BEGIN_EXTERN_C()
  76.  
  77. ZEND_API char *zend_strndup(const char *s, unsigned int length);
  78.  
  79. ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  80. ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  81. ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  82. ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  83. ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  84. ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  85. ZEND_API int _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  86.  
  87. /* Standard wrapper macros */
  88. #define emalloc(size)                    _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  89. #define efree(ptr)                        _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  90. #define ecalloc(nmemb,size)                _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  91. #define erealloc(ptr,size)                _erealloc((ptr), (size),0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  92. #define erealloc_recoverable(ptr,size)    _erealloc((ptr), (size),1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  93. #define estrdup(s)                        _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  94. #define estrndup(s,length)                _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  95. #define persist_alloc(p)                _persist_alloc((p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  96.  
  97. /* Relay wrapper macros */
  98. #define emalloc_rel(size)                    _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  99. #define efree_rel(ptr)                        _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  100. #define ecalloc_rel(nmemb, size)            _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  101. #define erealloc_rel(ptr, size)                _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  102. #define erealloc_recoverable_rel(ptr, size)    _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  103. #define estrdup_rel(s)                        _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  104. #define estrndup_rel(s, length)                _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  105. #define persist_alloc_rel(p)                _persist_alloc((p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
  106.  
  107. /* Selective persistent/non persistent allocation macros */
  108. #define pemalloc(size,persistent) ((persistent)?malloc(size):emalloc(size))
  109. #define pefree(ptr,persistent)  ((persistent)?free(ptr):efree(ptr))
  110. #define pecalloc(nmemb,size,persistent) ((persistent)?calloc((nmemb),(size)):ecalloc((nmemb),(size)))
  111. #define perealloc(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc((ptr),(size)))
  112. #define perealloc_recoverable(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc_recoverable((ptr),(size)))
  113. #define pestrdup(s,persistent) ((persistent)?strdup(s):estrdup(s))
  114.  
  115. #define safe_estrdup(ptr)  ((ptr)?(estrdup(ptr)):(empty_string))
  116. #define safe_estrndup(ptr,len) ((ptr)?(estrndup((ptr),(len))):(empty_string))
  117.  
  118. ZEND_API int zend_set_memory_limit(unsigned int memory_limit);
  119.  
  120. ZEND_API void start_memory_manager(ALS_D);
  121. ZEND_API void shutdown_memory_manager(int silent, int clean_cache);
  122.  
  123. #if ZEND_DEBUG
  124. ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  125. ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
  126. void zend_debug_alloc_output(char *format, ...);
  127. #define mem_block_check(ptr, silent) _mem_block_check(ptr, silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  128. #define full_mem_check(silent) _full_mem_check(silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
  129. #else
  130. #define mem_block_check(type, ptr, silent)
  131. #define full_mem_check(silent)
  132. #endif
  133.  
  134.  
  135. END_EXTERN_C()
  136.  
  137. #endif
  138.  
  139. /*
  140.  * Local variables:
  141.  * tab-width: 4
  142.  * c-basic-offset: 4
  143.  * End:
  144.  */
  145.